package com.xiaoxing.paimai.mvp.ui.fragment;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.jess.arms.base.BaseLazyFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.xiaoxing.gifloadingview.LoadingDialogUtil;
import com.xiaoxing.paimai.R;
import com.xiaoxing.paimai.di.component.DaggerHomeComponent;
import com.xiaoxing.paimai.di.module.HomeModule;
import com.xiaoxing.paimai.mvp.contract.HomeContract;
import com.xiaoxing.paimai.mvp.presenter.HomePresenter;
import com.xiaoxing.paimai.mvp.ui.activity.ScanQRCodeActivity;
import com.xiaoxing.paimai.mvp.ui.adapter.ChongDianGuiAdapter;
import com.xiaoxing.paimai.mvp.ui.entity.CangKuList;
import com.xiaoxing.paimai.mvp.ui.entity.ChongDianGui;
import com.xiaoxing.paimai.mvp.ui.entity.InfoByQRCodeMid;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import me.jessyan.armscomponent.commonsdk.core.BaseConstants;

import static android.app.Activity.RESULT_OK;
import static com.jess.arms.utils.Preconditions.checkNotNull;
import static me.jessyan.armscomponent.commonsdk.core.BaseConstants.SCAN_REQUEST_CODE;


public class HomeFragment extends BaseLazyFragment<HomePresenter> implements HomeContract.View {

    private static final int STOP = 0;
    private static final int THREADING = 1;
    private static final int POSTSUCCESS = 2;
    private static final int POSTERROR = 3;
    public static HomeFragment instance;
    public HashMap<String, HashMap<String, String>> mYuYueHashMap = new HashMap<>();
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.sp_cang_ku_list)
    Spinner mSpCangKuList;
    String scanResult = "";
    String scanResultSub = "";
    String resultStr = "";
    List<InfoByQRCodeMid> list_InfoByQRCodeMid = null;
    private List<String> data_list;
    private ArrayAdapter<String> arr_adapter;
    private List<ChongDianGui> mItems = new ArrayList();
    private List<CangKuList> mCangKuLists = new ArrayList();
    private List<ChongDianGui> mChongDianGuiList = new ArrayList();
    private MyHandler mMyHandler;
    private ChongDianGuiAdapter mAdapter;
    private List<String> list = new ArrayList<String>();
    private String mPlaceid = "";
    private InfoByQRCodeMid infoByQRCodeMid = new InfoByQRCodeMid(getActivity());

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerHomeComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .homeModule(new HomeModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_home, container, false);
        initRecyclerView(view);
        return view;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        instance = this;
        title.setText("主页");
        toolbar.setNavigationIcon(null);
        mMyHandler = new MyHandler();

    }

    @Override
    public void setData(@Nullable Object data) {

    }

    private void initRecyclerView(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
        mAdapter = new ChongDianGuiAdapter(getActivity(), mChongDianGuiList);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(mAdapter);
    }

    private void initSpCangKuList(List<CangKuList> cangKuLists) {

        if (cangKuLists != null && cangKuLists.size() > 0) {

            mPlaceid = cangKuLists.get(0).getPlaceid();
            setMplaceId();

            data_list = new ArrayList<String>();


            for (int i = 0; i < cangKuLists.size(); i++) {
                data_list.add(cangKuLists.get(i).getPlacename());
            }

            //适配器
            arr_adapter = new ArrayAdapter<String>(getActivity(), R.layout.simple_spinner_item_cang_ku, data_list);
            //设置样式
            arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            //加载适配器
            mSpCangKuList.setAdapter(arr_adapter);

            mSpCangKuList.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {//选择item的选择点击监听事件
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    mPlaceid = cangKuLists.get(arg2).getPlaceid();
                    setMplaceId();
                    getAvailable();
                }

                public void onNothingSelected(AdapterView<?> arg0) {
                }
            });
        }

    }

    private void setMplaceId() {

        mSharedPreferencesHelper.putString(BaseConstants.MPLACE_ID, mPlaceid);
    }

    private void getAvailable() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                // WSDL文档的URL，192.168.17.156为PC的ID地址
                String url = "http://" + getSpIP() + ":" + getSpPort()
                        + "/ws/ContainerService.asmx";
                String nameSpace = "http://tempuri.org/";
                // 定义调用的WebService方法名
                String methodName = "getAllAvailableChargeLight";
                String soapAction = nameSpace + methodName;
                try {

                    /****************** 调用webService ***********************/

                    // 设置连接参数
                    SoapObject request = new SoapObject(nameSpace, methodName);
                    request.addProperty("placeid", mPlaceid);

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// soap协议版本必须用SoapEnvelope.VER11（Soap
                    // V1.1）;

                    // 注意：这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice
                    // 不指定rpc方式则用true否则要用false
                    envelope.dotNet = true;

                    // envelope.setOutputSoapObject(request);//设置请求参数
                    envelope.bodyOut = request; // enveloper.bodyOut=request 与
                    // envelope.setOutputSoapObject(request)
                    // 效果相同。
                    // step4 创建HttpTransportSE对象
                    HttpTransportSE ht = new HttpTransportSE(url);
                    // step5 调用WebService
                    ht.call(soapAction, envelope); // 关键的一步，很多问题都在这一步调试时出现问题。要么是IIS有问题，要么是ksoap2相关参数没配置好。
                    if (envelope.getResponse() != null) {
                        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                        // if ("1".equals(response.toString())) {
                        String t = response.toString();

                        if (!TextUtils.isEmpty(t)) {
                            mItems.clear();
                            String[] arys = t.split("@");
                            for (int i = 0; i < arys.length; i++) {


                                String[] aary = arys[i].split("#");
                                ChongDianGui chongDianGui = new ChongDianGui();
                                if (i == 0) {
                                    chongDianGui.setImgPath(R.drawable.charge1);
                                }
                                if (i == 1) {
                                    chongDianGui.setImgPath(R.drawable.charge2);
                                }
                                if (i == 2) {
                                    chongDianGui.setImgPath(R.drawable.charge4);
                                }
                                if (i == 3) {
                                    chongDianGui.setImgPath(R.drawable.charge3);
                                }
                                if (aary[1].equals("JW7101")) {
                                    chongDianGui.setImgPath(R.drawable.charge3);
                                }
                                if (aary[1].equals("JW7102")) {
                                    chongDianGui.setImgPath(R.drawable.charge4);
                                }
                                chongDianGui.setId(aary[0]);
                                chongDianGui.setXingHao(aary[1]);
                                chongDianGui.setKeYongShuLiang(aary[2]);
                                mItems.add(chongDianGui);
                            }
                            mMyHandler.sendEmptyMessage(4);
                        }

                    }
                    /****************** 调用webService结束 ***********************/

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private String getSpIP() {
        return mSharedPreferencesHelper.getString(BaseConstants.SHE_ZHI_IP);
    }

    private String getSpPort() {
        return mSharedPreferencesHelper.getString(BaseConstants.SHE_ZHI_PORT);
    }

    @OnClick({R.id.store_btn_QRCode, R.id.store_url_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.store_btn_QRCode:
//                Intent openCameraIntent = new Intent(getActivity(), CaptureActivity.class);
//                startActivityForResult(openCameraIntent, 0);
                Intent newIntent = new Intent(getActivity(), ScanQRCodeActivity.class);
                mSharedPreferencesHelper.putInt(SCAN_REQUEST_CODE, 101);
                // 开始一个新的 Activity等候返回结果
                startActivityForResult(newIntent, 101);
                break;
            case R.id.store_url_submit:

                if (mYuYueHashMap.size() > 0) {
                    doOrder();
                } else {
                    ArmsUtils.snackbarText("至少要填入一个预约数量");
                }
                break;
        }

    }

    private void doOrder() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                // WSDL文档的URL，192.168.17.156为PC的ID地址
                String url = "http://" + getSpIP() + ":" + getSpPort()
                        + "/ws/ContainerService.asmx";
                String nameSpace = "http://tempuri.org/";
                // 定义调用的WebService方法名
                String methodName = "chargeLightAppointmentNew";
                String soapAction = nameSpace + methodName;
                try {

                    /****************** 调用webService ***********************/

                    // 设置连接参数
                    SoapObject request = new SoapObject(nameSpace, methodName);
                    // 增加属性参数。 将相关的函数参数放入到过程中。
                    String uid = mSharedPreferencesHelper.getString(BaseConstants.UID) + "";
                    String username = mSharedPreferencesHelper.getString(BaseConstants.USERNAME);
                    StringBuffer sbf = new StringBuffer();


                    for (Map.Entry<String, HashMap<String, String>> entryId : mYuYueHashMap.entrySet()) {

                        sbf.append(entryId.getKey());
                        HashMap<String, String> mXingHao = entryId.getValue();
                        for (Map.Entry<String, String> entryXingHao : mXingHao.entrySet()) {
                            sbf.append("#" + entryXingHao.getKey() + "#" + entryXingHao.getValue() + "#" + uid + "#" + mPlaceid + "@");
                        }
                    }

                    request.addProperty("info", ArmsUtils.cutLastString(sbf.toString()));
                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// soap协议版本必须用SoapEnvelope.VER11（Soap
                    // V1.1）;

                    // 注意：这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice
                    // 不指定rpc方式则用true否则要用false
                    envelope.dotNet = true;

                    // envelope.setOutputSoapObject(request);//设置请求参数
                    envelope.bodyOut = request; // enveloper.bodyOut=request 与
                    // envelope.setOutputSoapObject(request)
                    // 效果相同。
                    // step4 创建HttpTransportSE对象
                    HttpTransportSE ht = new HttpTransportSE(url);
                    // step5 调用WebService
                    ht.call(soapAction, envelope); // 关键的一步，很多问题都在这一步调试时出现问题。要么是IIS有问题，要么是ksoap2相关参数没配置好。
                    if (envelope.getResponse() != null) {
                        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                        // if ("1".equals(response.toString())) {
                        String t = response.toString();
                        if (!TextUtils.isEmpty(t)) {
                            Message msg = new Message();
                            try {
                                int num = Integer.parseInt(t);
                                msg.arg1 = num;
                                msg.what = 6;
                                mMyHandler.sendMessage(msg);
                            } catch (Exception ex) {
                                msg.obj = t;
                                msg.what = 7;
                                mMyHandler.sendMessage(msg);
                            }
                        }
                    }
                    /****************** 调用webService结束 ***********************/

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    protected void showAlert() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("提示");
        builder.setMessage(list.get(0) + "归还设备");//提示内容
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        final AlertDialog dialog = builder.create();
        dialog.show();
    }

    @Override
    protected void loadData() {
        getStorePlaceInfo();
        getUserReturnRemind();
    }

    /**
     * 获取仓库列表
     */
    private void getStorePlaceInfo() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                // WSDL文档的URL，192.168.17.156为PC的ID地址
                String url = "http://" + getSpIP() + ":" + getSpPort()
                        + "/ws/ContainerService.asmx";
                String nameSpace = "http://tempuri.org/";
                // 定义调用的WebService方法名
                String methodName = "getStorePlaceInfo";
                String soapAction = nameSpace + methodName;
                try {

                    /****************** 调用webService ***********************/

                    // 设置连接参数
                    SoapObject request = new SoapObject(nameSpace, methodName);

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// soap协议版本必须用SoapEnvelope.VER11（Soap
                    // V1.1）;

                    // 注意：这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice
                    // 不指定rpc方式则用true否则要用false
                    envelope.dotNet = true;

                    // envelope.setOutputSoapObject(request);//设置请求参数
                    envelope.bodyOut = request; // enveloper.bodyOut=request 与
                    // envelope.setOutputSoapObject(request)
                    // 效果相同。
                    // step4 创建HttpTransportSE对象
                    HttpTransportSE ht = new HttpTransportSE(url);
                    // step5 调用WebService
                    ht.call(soapAction, envelope); // 关键的一步，很多问题都在这一步调试时出现问题。要么是IIS有问题，要么是ksoap2相关参数没配置好。
                    if (envelope.getResponse() != null) {
                        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                        // if ("1".equals(response.toString())) {
                        String t = response.toString();

                        if (!TextUtils.isEmpty(t)) {
                            mItems.clear();
                            String[] arys = t.split("@");
                            for (int i = 0; i < arys.length; i++) {


                                String[] aary = arys[i].split("#");
                                CangKuList cangKuList = new CangKuList();

                                cangKuList.setPlaceid(aary[0]);
                                cangKuList.setPlacename(aary[1]);
                                cangKuList.setPlaceaddress(aary[2]);
                                cangKuList.setPlacecontactname(aary[3]);
                                cangKuList.setPlacecontactphone(aary[4]);

                                mCangKuLists.add(cangKuList);
                            }
                            mMyHandler.sendEmptyMessage(9);
                        }

                    }
                    /****************** 调用webService结束 ***********************/

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private void getUserReturnRemind() {

        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                // WSDL文档的URL，192.168.17.156为PC的ID地址
                String url = "http://" + getSpIP() + ":" + getSpPort()
                        + "/ws/ContainerService.asmx";
                String nameSpace = "http://tempuri.org/";
                // 定义调用的WebService方法名
                String methodName = "getUserReturnRemind";
                String soapAction = nameSpace + methodName;
                try {

                    /****************** 调用webService ***********************/

                    // 设置连接参数
                    SoapObject request = new SoapObject(nameSpace, methodName);
                    String uid = mSharedPreferencesHelper.getString(BaseConstants.UID);
                    request.addProperty("uid", uid);
                    request.addProperty("storetype", "1");
                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// soap协议版本必须用SoapEnvelope.VER11（Soap
                    // V1.1）;

                    // 注意：这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice
                    // 不指定rpc方式则用true否则要用false
                    envelope.dotNet = true;

                    // envelope.setOutputSoapObject(request);//设置请求参数
                    envelope.bodyOut = request; // enveloper.bodyOut=request 与
                    // envelope.setOutputSoapObject(request)
                    // 效果相同。
                    // step4 创建HttpTransportSE对象
                    HttpTransportSE ht = new HttpTransportSE(url);
                    // step5 调用WebService
                    ht.call(soapAction, envelope); // 关键的一步，很多问题都在这一步调试时出现问题。要么是IIS有问题，要么是ksoap2相关参数没配置好。
                    if (envelope.getResponse() != null) {
                        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                        // if ("1".equals(response.toString())) {
                        String t = response.toString();
                        if (!TextUtils.isEmpty(t)) {
                            String[] arys = t.split("@");
                            for (String item : arys) {
                                String[] aary = item.split("#");
                                list.add(aary[2]);
                            }
                            mMyHandler.sendEmptyMessage(8);
                        }
                    }
                    /****************** 调用webService结束 ***********************/

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mMyHandler != null) {
            mMyHandler = null;
        }
        if (instance != null) {
            instance = null;
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == 101) {
            Bundle bundle = data.getExtras();
            scanResult = bundle.getString("scan_result");

            scanResultSub = scanResult.substring(scanResult.lastIndexOf("?") + 1, scanResult.length());


            mSharedPreferencesHelper.putString(BaseConstants.SCAN_RESULT_SUB, scanResultSub);

            String sub = scanResultSub.split("=")[0];

            if (sub.equals("sid")) {

                new Thread() {
                    @Override
                    public void run() {

                        int uid = Integer.parseInt(mSharedPreferencesHelper.getString(BaseConstants.UID));
                        String LoginName = mSharedPreferencesHelper.getString(BaseConstants.USERNAME);
                        String path = scanResult + "&uid=" + uid + "_" + LoginName;

                        try {
                            // 1.定义请求url
                            URL url = new URL(path);
                            // 2.建立一个http的连接
                            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                            // 3.设置一些请求的参数
                            conn.setRequestMethod("POST");
                            conn.setRequestProperty("User-Agent",
                                    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
                            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                            String data1 = scanResultSub + "&uid=" + uid + "_" + LoginName;
                            conn.setRequestProperty("Content-Length", data1.length() + "");
                            conn.setConnectTimeout(5000);// 设置连接超时时间
                            conn.setReadTimeout(5000); // 设置读取的超时时间

                            // 4.一定要记得设置 把数据以流的方式写给服务器
                            conn.setDoOutput(true); // 设置要向服务器写数据
                            conn.getOutputStream().write(data1.getBytes());

                            int code = conn.getResponseCode(); // 服务器的响应码
                            // 200 OK
                            // //404
                            // 页面找不到
                            if (code == 200) {
                                Message m = new Message();
                                m.what = THREADING;
                                mMyHandler.sendMessage(m);
                            }

                        } catch (Exception e) {
                            // TODO: handle exception

                            String s = e.getStackTrace().toString();

                            Message m = new Message();
                            m.what = POSTERROR;
                            mMyHandler.sendMessage(m);
                        }

                    }
                }.start();

//				Intent in = new Intent(ListByQRCodeActivity.this,StoreListQRCOpenDoor.class);
//				in.putExtra("scanResult", scanResult);
//				startActivity(in);

            } else {

                new Thread() {
                    @Override
                    public void run() {

                        int uid = Integer.parseInt(mSharedPreferencesHelper.getString(BaseConstants.UID));

                        String spid = scanResultSub.substring(scanResultSub.lastIndexOf("=") + 1,
                                scanResultSub.length());

                        list_InfoByQRCodeMid = GetListInfoByQRCodeMidFromWebService(spid, uid, "1");

                        if (list_InfoByQRCodeMid.size() > 0) {
                            Message m = new Message();
                            m.what = STOP;
                            mMyHandler.sendMessage(m);
                        } else {
                            Message m = new Message();
                            m.what = THREADING;
                            mMyHandler.sendMessage(m);
                        }

                    }
                }.start();
            }

        }
    }


    // 获取基本信息
    private List<InfoByQRCodeMid> GetListInfoByQRCodeMidFromWebService(String spid, int uid, String page) {

        List<InfoByQRCodeMid> list = null;
        try {
            /****************** 调用webService ***********************/
            // 调用.net 的WebService.
            String nameSpace = "http://tempuri.org/";
            String methodName = "getMyOut";

            String url = "http://" + getSpIP() + ":" + getSpPort()
                    + "/ws/ContainerService.asmx";
            String soapAction = nameSpace + methodName;

            // 设置连接参数
            SoapObject request = new SoapObject(nameSpace, methodName);

            // 增加属性参数。 将相关的函数参数放入到过程中。
            request.addProperty("spid", spid);
            request.addProperty("uid", uid);
            request.addProperty("page", page);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// soap协议版本必须用SoapEnvelope.VER11（Soap
            // V1.1）;

            // 注意：这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice
            // 不指定rpc方式则用true否则要用false
            envelope.dotNet = true;

            // envelope.setOutputSoapObject(request);//设置请求参数
            envelope.bodyOut = request; // enveloper.bodyOut=request 与
            // envelope.setOutputSoapObject(request)
            // 效果相同。
            // step4 创建HttpTransportSE对象
            HttpTransportSE ht = new HttpTransportSE(url);
            // step5 调用WebService
            ht.call(soapAction, envelope); // 关键的一步，很多问题都在这一步调试时出现问题。要么是IIS有问题，要么是ksoap2相关参数没配置好。
            if (envelope.getResponse() != null) {
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

                String returnStr = response.toString();

                if ("" != returnStr) {
                    returnStr = returnStr.substring(returnStr.lastIndexOf("["), returnStr.length());

                    returnStr = returnStr.replace("\\", "");

                    list = infoByQRCodeMid.getListFromJSON(returnStr);

                }

            }
            /****************** 调用webService结束 ***********************/

        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }

    class MyHandler extends Handler {
        public MyHandler() {
        }

        public MyHandler(Looper L) {
            super(L);
        }

        // 子类必须重写此方法，接受数据
        @Override
        public void handleMessage(Message msg) {
            LoadingDialogUtil.dismissDialog();
            switch (msg.what) {
                case THREADING:
                    break;
                case POSTERROR:
                    break;
                case STOP:
                    break;
                case 4:
                    mChongDianGuiList.clear();
                    mChongDianGuiList.addAll(mItems);
                    mAdapter.notifyDataSetChanged();
                    break;
                case 6:
                    Toast.makeText(getActivity(), "预订成功,预约码为：" + msg.arg1, Toast.LENGTH_LONG).show();
                    getAvailable();
                    break;
                case 7:
                    Toast.makeText(getActivity(), "" + msg.obj, Toast.LENGTH_LONG).show();
                    break;
                case 8:
                    showAlert();
                    break;
                case 9://仓库下拉选
                    initSpCangKuList(mCangKuLists);
//                    getAvailable();

                    break;

                default:
                    break;
            }
        }


    }

}
